import {Entity, Column, OneToMany, JoinTable, ManyToMany, Index} from "typeorm";
import {CommonEntity} from "~/common/entity/common.entity";
import {CatalogEntity} from "~/modules/books/catalog.entity";
import {AuthorEntity} from "~/modules/books/author.entity";

@Index(["id"])
@Entity({name: "books_book"})
export class BookEntity extends CommonEntity {

  @Column()
  imageUrl: string;

  @Column({type: "varchar", length: 20, comment: "书名"})
  name: string;

  @Column({type: "text", comment: "简介"})
  introduction: string;

  @OneToMany(() => CatalogEntity, catalog => catalog.book)
  catalogs: CatalogEntity[];

  @ManyToMany(() => AuthorEntity, author => author.books)
  @JoinTable()
  authors: AuthorEntity[];
}
